package com.itheima.a01myexception;

import java.util.Scanner;

public class ExceptionDemo13 {
    public static void main(String[] args) {
        /**
         * 学生的名字长度为[3, 10]
         * 学生的年龄大小为[18, 40];
         */
        Scanner sc = new Scanner(System.in);

        Student stu = new Student();

        while (true) {
            try {
                System.out.println("请输入学生的名字");
                String name = sc.nextLine();
                stu.setName(name);
                System.out.println("请输入学生的年龄");
                String ageStr = sc.nextLine();
                int age = Integer.parseInt(ageStr);
                stu.setAge(age);
                break;
            } catch (NumberFormatException e) {
                System.out.println("年龄的格式有异常");
            } catch (RuntimeException e) {
                System.out.println("名字的长度或者年龄的大小有异常");
            }
        }

        System.out.println(stu.toString());

    }
}
